﻿package ui{
	import flash.display.Sprite
	import flash.display.Stage
	import flash.events.Event
	import flash.text.TextFormatAlign
	
	import flash.events.MouseEvent
	
	import sample.ui.components.*
	public class Login extends Sprite{
		private var _stage:Stage
		private var base:Box 
		function Login(stage:Stage){
			_stage = stage;
			
			var pwdError:Label = new Label("", TextFormatAlign.RIGHT, 12, 0xff0000)
			var usernameError:Label = new Label("", TextFormatAlign.RIGHT, 12, 0xff0000)
			
			base = new Box().fill(0xFFFFFF,0.8).add(
				new Box().fill(0x000000,.5,15).margin(10,10,10,10).minSize(300,0).add(
					new Box().fill(0xffffff,1,5).margin(10,10,10,10).minSize(300,0).add(
						new Rows(
							new Label("Login", TextFormatAlign.CENTER, 20),
							new Columns().margin(0,5,0,5).spacing(3).add(
								new Label("Username", TextFormatAlign.RIGHT),
								new Input("", TextFormatAlign.LEFT)
							),
							usernameError,
							new Columns().margin(0,5,0,5).spacing(3).add(
								new Label("Password", TextFormatAlign.RIGHT),
								new Input("", TextFormatAlign.LEFT, 12, true)
							),
							pwdError,
							new Columns().margin(10).spacing(10).add(
								new TextButton("Cancel", Hide),
								new TextButton("Login", function(){ 
									pwdError.text = "Wrong password";
									usernameError.text = "Unknown Username";
									realign() 
								})
							)
						).spacing(3)
					)
				)
			)
			
			addChild(base)
			realign();
		}
		
		public function Show(e:Event = null):void{
			_stage.addChild(this);
			_stage.addEventListener(Event.RESIZE, realign)
			realign()
		}
		
		public function Hide(e:Event = null):void{
 			_stage.removeChild(this);
			_stage.removeEventListener(Event.RESIZE, realign)
		}
		
		private function realign(e:Event = null){
			
			base.reset();
			base.width = _stage.stageWidth
			base.height = _stage.stageHeight
			
		}
	}	
}